package com.isc.tcpCommunication01;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

/**
 * 1.编写一个服务器端和客户端
 * 2.服务器端在9999端口监听
 * 3.客户端连接到服务器端，发送"hello,server",然后退出
 * 4.服务器端接收到客户端发送的信息，输出，并退出
 */
public class Client {
    public static void main(String[] args) throws IOException {
        //客户端发送请求给服务器端
        Socket socket = new Socket(InetAddress.getLocalHost(), 9999);
        System.out.println("发送连接请求...");

        //发送数据
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("hello,server".getBytes());
        System.out.println("发送信息成功...");

        //关闭资源
        outputStream.close();
        socket.close();
        System.out.println("客户端断开连接...");
    }
}
